package com.example.administrator.yuejian2.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.bean.TrainOrderBean;
import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.example.administrator.yuejian2.other.Url.IMAGEURL;

public class TrainOrderDetailAdapter extends RecyclerView.Adapter {



    private Context context;
    private List<TrainOrderBean> list;
    private LayoutInflater layoutInflater;

    public TrainOrderDetailAdapter(Context context) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
    }

    public void getTrainorderdetailList(List<TrainOrderBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.train_order_detail_item, parent, false);
        return new TrainOrderDetailViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        TrainOrderDetailViewHolder viewHolder = (TrainOrderDetailViewHolder) holder;
        final TrainOrderBean bean = list.get(position);
        viewHolder.trainOrderDetailName.setText(bean.getTrain_name());
        viewHolder.trainOrderDetailNum.setText(bean.getTrainorder_num());
        viewHolder.trainOrderDetailNumber.setText(bean.getTrainorder_number());
        viewHolder.trainOrderDetailTime.setText(bean.getTrainorder_time());
        viewHolder.trainOrderDetailPrice.setText(bean.getTrainorder_amount());
        viewHolder.trainOrderDetailTel.setText(bean.getTrainorder_tel());
        viewHolder.trainOrderDetailAddress.setText(bean.getTrain_address());
        viewHolder.trainOrderDetailAmount.setText(bean.getTrainorder_amount());
        if (bean.getTrainorder_state().equals("1"))
        {
            viewHolder.trainorderflag.setText("审核已通过");
        }
        else{
            viewHolder.trainorderflag.setText("审核未通过");
        }

        Picasso.with(context)
                .load(IMAGEURL + bean.getTrain_pic())
                .placeholder(R.mipmap.loading)
                .into(viewHolder.trainOrderDetailPic);
    }

    @Override
    public int getItemCount() {
        if (list == null) {
            return 0;
        } else {
            return list.size();
        }
    }


    class TrainOrderDetailViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.train_order_detail_pic)
        ImageView trainOrderDetailPic;
        @BindView(R.id.train_order_detail_name)
        TextView trainOrderDetailName;
        @BindView(R.id.train_order_detail_num)
        TextView trainOrderDetailNum;
        @BindView(R.id.train_order_detail_price)
        TextView trainOrderDetailPrice;
        @BindView(R.id.train_order_detail_number)
        TextView trainOrderDetailNumber;
        @BindView(R.id.train_order_detail_time)
        TextView trainOrderDetailTime;
        @BindView(R.id.train_order_detail_tel)
        TextView trainOrderDetailTel;
        @BindView(R.id.train_order_detail_address)
        TextView trainOrderDetailAddress;
        @BindView(R.id.train_order_detail_amount)
        TextView trainOrderDetailAmount;
        @BindView(R.id.trainorderflag)
        TextView trainorderflag;

        public TrainOrderDetailViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
